package org.wjk.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.wjk.pojo.vo.ResponseRes;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Slf4j
public class ResponseUtils {
    public static void convertToJson(HttpServletResponse response, ResponseRes res) throws IOException {
        ObjectMapper mapper = new  ObjectMapper();
        String resR=mapper.writeValueAsString(res);
        log.debug("序列化的json串为{}",resR);
        response.setContentType("application/json;charset=utf-8");
        PrintWriter writer=response.getWriter();
        writer.write(resR);
        writer.close();
    }
}
